package com.chilly.other.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 一个字符串（以“,”分隔），用lambda表达式将字符串解析成List
 *
 * Created by Chilly Cui on 2020/12/15.
 */
public class StringSplitDemo {
    public static void main(String[] args) {
        String s = "a,1,b,2";
        List<String> list = Arrays.stream(s.split(",")).map(ss -> ss.trim()).collect(Collectors.toList());
        List<String> list2= Arrays.stream(s.split(",")).map(ss -> ss.trim()).collect(Collectors.toCollection(ArrayList::new));
        System.out.println(list); //[a, 1, b, 2]
        System.out.println(list2);//[a, 1, b, 2]
    }
}
